<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start">
      <el-input
        placeholder="车务编号"
        style="width:20%;margin-right:10px"
        v-model="carlist.carserverno"
        clearable
      ></el-input>
      <el-input
        placeholder="牌照"
        style="width:20%;margin-right:10px"
        v-model="carno"
        clearable
      ></el-input>
      <!--
      <selectcarnumber
        placeholder="牌照"
        @getpersonid2="getpersonid2"
        :itemtype="2"
        style="width:20%;margin-right:10px"
      ></selectcarnumber>
      -->
      <el-input
        placeholder="办理人"
        style="width:20%;margin-right:10px"
        v-model="carlist.holder"
        clearable
      ></el-input>
      <!-- <searchperson @getpersonid="getpersonid" style="width:20%;margin-right:10px"></searchperson> -->
      <el-select
        v-model="carlist.servertype"
        placeholder="请选择车务类型"
        style="margin-right:10px"
        clearable
      >
        <el-option
          v-for="item in itemdata"
          :key="item.value"
          :label="item.hash.code_name"
          :value="item.hash.code_id"
        ></el-option>
      </el-select>
      <el-date-picker
        v-model="carlist.servertime"
        style="width:32%;margin-right:20px"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="办理开始日期"
        endPlaceholder="办理结束日期"
        valueFormat="yyyy-MM-dd"
        placeholder="办理时间"
        clearable
      >
      </el-date-picker>
      <!-- <el-date-picker
        v-model="carlist.servertime"
        type="date"
        style="margin-right:10px"
        placeholder="办理日期"
        valueFormat="yyyy-MM-dd"
      ></el-date-picker> -->

      <el-button size="mini" type="primary" @click="getservicelist">搜索</el-button>
    </el-row>

    <el-row>
      <el-button size="mini" @click="addcarsev">添加车务信息</el-button>
      <el-button size="mini" type="primary" @click="carmainedit">编辑</el-button>
      <el-button size="mini" type="success" @click="deleteservice">删除</el-button>
    </el-row>
    <el-divider></el-divider>
    <servicetable :tableData="carservicedata" :itemvals.sync="itemvals" :pagobj.sync="pagobj" :itemval1.sync="itemval1"></servicetable>

    <addservice
      v-if="isaddcarsev"
      :itemdata="itemdata"
      :chousebtn="btnvalue"
      :chouseval="itemvals"
      :addcarsever.sync="changezt"
    ></addservice>
  </div>
</template>

<script>
import addservice from '~/components/carmanager/carservice/addservice.vue';
import servicetable from '~/components/carmanager/carservice/servicetable.vue';
import selectcarnumber from '~/components/common/selectcarnumber.vue';
import searchperson from '~/components/common/searchperson.vue';

export default {
  components: {
    servicetable,
    addservice,
    selectcarnumber,
    searchperson,
  },
  data() {
    return {
      dialogVisible: false,
      isaddcarsev: false,
      ts: this.newStore(),
      itemval1: [],
      carlist: {
        carserverno: '', // 车务编号
        carno: '', // 牌照
        servertype: '', // 服务类型
        servertime: ['', ''], // 办理时间
        holder: '', // 办理人
      },
      // 分页
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      carid: '',
      changezt: {},
      itemdata: [], // 获取车务类型
      carservicedata: [], // 车务列表
      itemvals: [], // 获得表格选中信息
      btnvalue: 0,
      carsrverid: [], // 选中的数组id
    };
  },
  created() {
    this.getservicelist();
    this.getitem();
  },
  watch: {
    changezt() {
      this.getservicelist();
    },
  },
  methods: {
    // 获取cardid
    getpersonid2(val) {
      // this.carid = val.id;
      this.carlist.carno = val.id;
    },
    // 获取负责人
    // getpersonid(val) {
    //   this.carlist.carholder = val.id;
    // },
    // 编辑
    carmainedit() {
      this.btnvalue = 2;
      if (this.itemval1.length == 1) {
        this.reload('isaddcarsev');
      } else if (this.itemval1.length == 0) {
        this.$message('请先勾选一个车务信息');
      } else {
        this.$message('只能选择一个车务信息进行修改');
      }
    },
    // 删除
    deleteservice() {
      if (this.itemval1.length > 0) {
        this.$confirm(`是否删除${this.itemval1.length}车辆维修信息?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          for (let i = 0; i < this.itemval1.length; i++) {
            this.carsrverid.push(this.itemval1[i].hash.carserverid);
          }
          // console.log(this.carsrverid, "999999");

          const req = {
            handle:
              '0E56125B90D2898AC5EC199397E64227ABB3EE25D9D8F0F4BFF0B9210751F692',
            carserverid: this.carsrverid,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getservicelist();
            }
          });
        });
      } else {
        this.$message('请先选择删除信息');
      }
    },
    // 获取车务类型
    getitem() {
      const req = {
        handle:
          '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid: '0302',
        codetype: '03',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.itemdata = ts.d.data.operation1;

          // console.log(this.itemdata, "3");
        }
      });
    },
    // 获取车务列表
    getservicelist() {
      const req = {
        handle:
          '0E56125B90D2898A610E7AD0194EDF3BE9576D3834F5E43944B455B1B2775577',
        carserverno: this.carlist.carserverno,
        carno: this.carlist.carno,
        servertype: this.carlist.servertype,
        servertimes: this.carlist.servertime[0],
        servertimee: this.carlist.servertime[1],
        holder: this.carlist.holder,
        start: (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize,
        limit: this.pagobj.pagesize,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          console.log(ts.d.data);
          this.carservicedata = ts.d.data.operation1;
          this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
          // this.carlist = {};
        }
      });
    },
    // 公共组件刷新
    reload(partsname) {
      // console.log(partsname);

      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    // 点击添加车务信息
    addcarsev() {
      this.btnvalue = 1;

      this.reload('isaddcarsev');
    },
  },
};
</script>

